#include <iostream>

using namespace std;
typedef long long LL;
const int N = 15;
LL s[N], b[N];
int n;
int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> s[i] >> b[i];
	LL ret = 1e9;
	for (int st = 1; st < (1 << n); st++)
	{
		LL x = 1, y = 0;
		for (int i = 0; i < n; i++)
		{
			if ((st >> i) & 1)
			{
				x *= s[i];
				y += b[i];
			}
		}
		ret = min(ret, abs(x - y));
	}
	cout << ret << endl;
	return 0;
}